# test_ps2.s
# connect4-nios2 project
#
# a simple main function to test the ps2.s functions (recieve keyboard input)
#
.equ UART_ADDR, 0xff10f0
.equ ADDR_7SEG, 0xff1100

.global main
.text

main:

	call PS2_CLEAR_BUF

	movia r8, ADDR_7SEG
	stwio r0, 0(r8)		# clear 7-seg displays
	
loop:
	call PS2_RECV
	mov r4, r2
	call PS2_STOR_BUF
	#call SEND_UART_CHAR

	br loop

SEND_UART_CHAR:
	# send char stored in r4

	movia r8, UART_ADDR
	WR_WAIT_1:
		ldwio r9, 4(r8)	# read control reg
		andi r9, r9, 0xffff0000	# get upper half
		beq r9, r0, WR_WAIT_1
	andi r4, r4, 0xFF
	stwio r4, 0(r8)	# write char to uart
	
	ret

